package preproc;
import java.awt.image.BufferedImage;
import java.util.Vector;

import segmentation.CharInfo;
import textPixelId.ClusterInfo;
import utils.Utils;


public class Image {
	public BufferedImage originalImage;
	public int[][] intensity;
	
	
	// contains, for each pixel, the cluster index to which it belongs to
	public int[][] clustered;
	public int maxClusterIdx;
	
	// cluster info, sorted according to the number of pixels
	public Vector<ClusterInfo> clusters;	
	
	// chars
	public Vector<CharInfo> chars = new Vector<CharInfo>();
	
	public int getWidth() {
		return intensity[0].length;
	}
	public int getHeight() {
		return intensity.length;
	}
	
	public BufferedImage greyscaleToImage() {
		return Utils.arrayToImage(intensity);
	}
	
	public void showGreyscale(String title) {
		Utils.showImage(greyscaleToImage(), title);
	}
	
	public BufferedImage imageWithBoxes() {
		BufferedImage img = Utils.arrayToImage(intensity);
		for (int i=0; i<chars.size(); i++) {
			for (int r=chars.get(i).cluster.r0; r<=chars.get(i).cluster.r1; r++) {
				img.setRGB(chars.get(i).cluster.c0, r, 255<<16);
				img.setRGB(chars.get(i).cluster.c1, r, 255<<16);
			}
			for (int c=chars.get(i).cluster.c0; c<=chars.get(i).cluster.c1; c++) {
				img.setRGB(c, chars.get(i).cluster.r0, 255<<16);
				img.setRGB(c, chars.get(i).cluster.r1, 255<<16);
			}
		}
		return img;
	}
	public void showImageWithBoxes() {
		Utils.showImage(imageWithBoxes(), "char boxes");
	}
}
